var Adv_skd=require("./Adv_skd")

var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2WeChatConstant = require("WeChatConstant");
var $2ADManager = require("ADManager");
var $2pvzChannel = require("pvzChannel");
var $2BundleManager = require("BundleManager");
var $2DataManager = require("DataManager");
var $2PlantMgr = require("PlantMgr");
var $2UIManager = require("UIManager");
var $2UserDataManager = require("UserDataManager");
var $2TaSdk = require("TaSdk");
var $2MyUtils = require("MyUtils");
var $2MenuUI = require("MenuUI");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_SignUI = /* */function (_cc$Component67) {
  babel_inherits(y, _cc$Component67);
  var _super83 = babel_createSuper(y);
  function y() {
    var _this193;
    babel_classCallCheck(this, y);
    _this193 = _super83.apply(this, arguments);
    _this193.signPanel = null;
    _this193.video1 = null;
    _this193.rewardType = {
      rewardType: 0,
      rare: 0,
      number: 0,
      plantID: 0
    };
    return _this193;
  }
  babel_createClass(y, [{
    key: "onLoad",
    value: function onLoad() {
 Adv_skd.default.instance.hideAllAdv();
      Adv_skd.default.instance.showInterstitialAd();
      Adv_skd.default.instance.showGridAdRight();
      Adv_skd.default.instance.showGridAdLeft();

      this.refreshSignPanel();
      this.getRewardInfo($2UserDataManager.default.instance.signDay);
      $2TaSdk.default.instance.postEvent("System", {
        system: "签到"
      });
      this.initPlatform();
    }
  }, {
    key: "refreshSignPanel",
    value: function refreshSignPanel() {
      for (var _e104 = 0; _e104 < 7; _e104++) {
        if (0 == $2UserDataManager.default.instance.signDay && $2UserDataManager.default.instance.signTimes > 0) {
          this.signPanel.children[_e104].getChildByName("Mask").active = true;
          this.signPanel.children[_e104].getChildByName("Spine").active = false;
          1 != _e104 && 6 != _e104 || (this.signPanel.children[_e104].children[0].active = true);
        } else {
          if (_e104 < $2UserDataManager.default.instance.signDay) {
            this.signPanel.children[_e104].getChildByName("Mask").active = true, this.signPanel.children[_e104].getChildByName("Spine").active = false, 1 != _e104 && 6 != _e104 || (this.signPanel.children[_e104].children[0].active = true);
          }
          if (_e104 == $2UserDataManager.default.instance.signDay && 0 == $2UserDataManager.default.instance.signTimes) {
            this.signPanel.children[_e104].getChildByName("Tip").active = true;
          } else {
            this.signPanel.children[_e104].getChildByName("Tip").active = false;
          }
        }
      }
    }
  }, {
    key: "onClickSign",
    value: function onClickSign(e, t) {
      if ($2UserDataManager.default.instance.signTimes > 0) {
        $2UIManager.default.instance.showToast("已经签到过了, 请明天再来");
      } else if ($2UserDataManager.default.instance.signDay == parseInt(t) - 1) {
        $2TaSdk.default.instance.postEvent("SignIn", {
          Day: $2UserDataManager.default.instance.signDay,
          Way: 1
        });
        $2UserDataManager.default.instance.signDay++;
        $2UserDataManager.default.instance.signTimes = 1;
        this.showReward();
      } else {
        $2UIManager.default.instance.showToast("当天奖励未领取！");
      }
    }
  }, {
    key: "getReward",
    value: function getReward() {
      var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
      switch ($2UserDataManager.default.instance.signDay) {
        case 0:
          $2UserDataManager.default.instance.getPlant(20);
          1 == e && $2UserDataManager.default.instance.getPlant(20);
          break;
        case 1:
          $2UserDataManager.default.instance.gold += 5e3;
          1 == e && ($2UserDataManager.default.instance.gold += 5e3);
          break;
        case 2:
          $2UserDataManager.default.instance.getPlant(22);
          1 == e && $2UserDataManager.default.instance.getPlant(22);
          break;
        case 3:
          $2UserDataManager.default.instance.diamond += 100;
          1 == e && ($2UserDataManager.default.instance.diamond += 100);
          break;
        case 4:
          $2UserDataManager.default.instance.setPlantChip(19, 10);
          1 == e && $2UserDataManager.default.instance.setPlantChip(19, 10);
          break;
        case 5:
          $2UserDataManager.default.instance.gold += 15e3;
          1 == e && ($2UserDataManager.default.instance.gold += 15e3);
          break;
        case 6:
          $2UserDataManager.default.instance.diamond += 300;
          1 == e && ($2UserDataManager.default.instance.diamond += 300);
      }
      this.refreshSignPanel();
      this.node.getChildByName("RewardUI").active = false;
    }
  }, {
    key: "getRewardInfo",
    value: function getRewardInfo(e) {
      switch (e) {
        case 0:
          this.rewardType.rare = 1;
          this.rewardType.rewardType = "c";
          this.rewardType.number = 5e3;
          break;
        case 1:
          this.rewardType.rare = 5;
          this.rewardType.rewardType = "b";
          this.rewardType.plantID = 22;
          break;
        case 2:
          this.rewardType.rare = 2;
          this.rewardType.rewardType = "c";
          this.rewardType.number = 100;
          break;
        case 3:
          this.rewardType.rare = 5;
          this.rewardType.rewardType = "a";
          this.rewardType.number = 10;
          this.rewardType.plantID = 19;
          break;
        case 4:
          this.rewardType.rare = 1;
          this.rewardType.rewardType = "c";
          this.rewardType.number = 15e3;
          break;
        case 5:
          this.rewardType.rare = 2;
          this.rewardType.rewardType = "c";
          this.rewardType.number = 300;
          break;
        case 6:
          this.rewardType.rare = 5;
          this.rewardType.rewardType = "b";
          this.rewardType.plantID = 20;
      }
      return e;
    }
  }, {
    key: "showReward",
    value: function showReward() {
      var _this194 = this;
      var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
      this.node.getChildByName("RewardUI").active = true;
      if ("a" == this.rewardType.rewardType) {
        this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("TipLabel").active = false;
        this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("Chip").active = true;
        this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("Num").active = true;
        this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("PlantIcon").active = true;
        this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("PlantAni").active = false;
        this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("Bg").active = true;
        this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("Num").getComponent(cc.Label).string = "X" + this.rewardType.number;
        this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("Bg").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ShopUI/s" + this.rewardType.rare, cc.SpriteFrame);
        this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("PlantIcon").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "PlantIcon/p_" + this.rewardType.plantID, cc.SpriteFrame);
      } else if ("b" == this.rewardType.rewardType) {
        if ($2UserDataManager.default.instance.plantLock.includes(this.rewardType.plantID) && !$2DataManager.default.instance.newPlant.includes(this.rewardType.plantID)) {
          this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("TipLabel").active = true;
        } else {
          this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("TipLabel").active = false;
        }
        this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("Chip").active = false;
        if (1 != this.rewardType.number && 0 != this.rewardType.number) {
          this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("Num").getComponent(cc.Label).string = "X" + this.rewardType.number;
        } else {
          this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("Num").active = false;
        }
        this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("PlantIcon").active = false;
        this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("PlantAni").active = true;
        this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("Bg").active = false;
        if ($2BundleManager.default.instance.getBundleRes("Spine", "plant/" + $2PlantMgr.default.instance().getPlant(this.rewardType.plantID).dragonName + "/" + $2PlantMgr.default.instance().getPlant(this.rewardType.plantID).dragonName, sp.SkeletonData)) {
          this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("PlantAni").getComponent(sp.Skeleton).skeletonData = $2BundleManager.default.instance.getBundleRes("Spine", "plant/" + $2PlantMgr.default.instance().getPlant(this.rewardType.plantID).dragonName + "/" + $2PlantMgr.default.instance().getPlant(this.rewardType.plantID).dragonName, sp.SkeletonData), this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("PlantAni").getComponent(sp.Skeleton).setAnimation(0, "daiji", true);
        } else {
          $2BundleManager.default.instance.loadBundleRes("Spine", "plant/" + $2PlantMgr.default.instance().getPlant(this.rewardType.plantID).dragonName + "/" + $2PlantMgr.default.instance().getPlant(this.rewardType.plantID).dragonName, sp.SkeletonData, function () {
            _this194.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("PlantAni").getComponent(sp.Skeleton).skeletonData = $2BundleManager.default.instance.getBundleRes("Spine", "plant/" + $2PlantMgr.default.instance().getPlant(_this194.rewardType.plantID).dragonName + "/" + $2PlantMgr.default.instance().getPlant(_this194.rewardType.plantID).dragonName, sp.SkeletonData);
            _this194.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("PlantAni").getComponent(sp.Skeleton).setAnimation(0, "daiji", true);
          });
        }
      } else {
        this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("Chip").active = false;
        this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("PlantIcon").scale = 1;
        this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("Num").getComponent(cc.Label).string = "X" + this.rewardType.number;
        this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("TipLabel").active = false;
        if (1 == this.rewardType.rare) {
          this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("PlantIcon").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ui/a034", cc.SpriteFrame);
        } else {
          this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("PlantIcon").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ui/a033", cc.SpriteFrame);
        }
      }
      e && (this.node.getChildByName("RewardUI").getChildByName("RewardBtnPanel").children[1].active = false);
      var t = this.node.getChildByName("RewardUI").getChildByName("RewardBtnPanel").children[0];
      if ($2pvzChannel.pvzChannel.instance().channel.indexOf("wx") >= 0 && $2pvzChannel.pvzChannel.instance().getCtrl("p1")) {
        t.active = false;
        this.scheduleOnce(function () {
          t.active = true;
        }, $2pvzChannel.pvzChannel.instance().getCtrl("p1"));
        $2pvzChannel.pvzChannel.instance().getCtrl("p4") && (this.video1.active = false);
      }
    }
  }, {
    key: "onClickVideoBtn",
    value: function onClickVideoBtn(e, t) {
      var _this195 = this;
      $2pvzChannel.pvzChannel.instance().showVideo({
        sucCall() {
          $2UserDataManager.default.instance.signTimes = 2;
          _this195.getReward(true);
        },
        failCall() {},
        endCall() {}
      });
    }
  }, {
    key: "onClickCloseBtn",
    value: function onClickCloseBtn() {
 Adv_skd.default.instance.hideAllAdv();

      $2UIManager.default.instance.closeUI("SignUI");
      $2UIManager.default.instance.uiList.MenuUI.getComponent($2MenuUI.default).showNode();
      if ($2ADManager.default.instance.sdkType == $2ADManager.SDK_TYPE.WeChat) {
        $2MyUtils.MyUtils.probability($2WeChatConstant.default.mainInster) && $2ADManager.default.instance.showInsert();
        $2ADManager.default.instance.hideNative(2);
        $2ADManager.default.instance.hideNative(3);
        $2ADManager.default.instance.showNative(0);
        $2ADManager.default.instance.hideNative(1);
      }
    }
  }, {
    key: "initPlatform",
    value: function initPlatform() {
      switch ($2ADManager.default.instance.sdkType) {
        case $2ADManager.SDK_TYPE.WeChat:
          $2ADManager.default.instance.showNative(1);
          $2ADManager.default.instance.hideNative(0);
          $2ADManager.default.instance.showNative(2);
          $2ADManager.default.instance.showNative(3);
      }
    }
  }]);
  return y;
}(cc.Component);
cc__decorate([ccp_property(cc.Node)], def_SignUI.prototype, "signPanel", undefined);
cc__decorate([ccp_property(cc.Node)], def_SignUI.prototype, "video1", undefined);
def_SignUI = cc__decorate([ccp_ccclass], def_SignUI);
exports.default = def_SignUI;